game_manager
{
	spawn
	{
		// Set scenario information
		wm_axis_respawntime 30
		wm_allied_respawntime 20
		wm_number_of_objectives 8
		wm_set_round_timelimit 15
		
		//mapscript by Dersaidin
		
		// 0  is axis
		wm_set_defending_team 0
		wm_setwinner 0
		
		//Cap obj
		wm_objective_status 1 1 0
		wm_objective_status 1 0 0
		//Blow door
		wm_objective_status 2 1 0
		wm_objective_status 2 0 0
		//Flag
		wm_objective_status 3 1 0
		wm_objective_status 3 0 1
		//CP
		wm_objective_status 4 1 0
		wm_objective_status 4 0 1
		//Sidedoor
		wm_objective_status 5 1 0
		wm_objective_status 5 0 1
		//Generator
		wm_objective_status 6 1 0
		wm_objective_status 6 0 0
		//TruckBarriers
		wm_objective_status 7 1 0
		wm_objective_status 7 0 0
		//Stealtruck
		wm_objective_status 8 1 0
		wm_objective_status 8 0 0
		
		//main objective is to cap docs
		wm_set_main_objective 1 1
		wm_set_main_objective 1 0
		
		// Cap obj
		accum 1 set 0
		//Blow door
		globalaccum 2 set 0
		//Flag, 0 is axis
		globalaccum 3 set 0
		//CP build once
		globalaccum 4 set 0
		//Sidedoor destroyed
		globalaccum 5 set 0
		//Allied CP _IS_ built
		globalaccum 6 set 0
		//Truck is built
		globalaccum 7 set 0
		
		setautospawn "Allied first spawn"	1	// Set Allies to forward spawn
		setautospawn "Axis rear spawn"	0	// Set Axis to forward spawn
		setstate axis1spawn_wobj invisible
		wait 500
		trigger self startvos
		trigger rollerdoor4 do_up
      delete
      {
         origin "2100 -371 128"   
      }

	}
	
	trigger startvos
	{
		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "radar_axis_entrances_defend"
		//wm_addteamvoiceannounce 0 "radar_axis_bunker_stop"
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"

		wm_addteamvoiceannounce 1 "radar_allies_entrances_destroy"
		//wm_addteamvoiceannounce 1 "radar_allies_bunker_capture"

		wm_teamvoiceannounce 0 "radar_axis_entrances_defend"
		//wm_teamvoiceannounce 0 "radar_axis_bunker_stop"
		wm_teamvoiceannounce 0 "axis_hq_compost_construct"

		wm_teamvoiceannounce 1 "radar_allies_entrances_destroy"
		//wm_teamvoiceannounce 1 "radar_allies_bunker_capture"
		// *---------------------------------------------------------------------------------*
	}
	
	trigger cap_truck
	{
		//objective set to complete
		wm_objective_status 1 1 1
		wm_objective_status 1 0 2
		//check set to true
		accum 1 set 1
		wm_announce "Allied team has escaped"
		trigger game_manager checkgame
	}
	
	
	trigger checkgame
	{
		accum 1 abort_if_not_equal 1
		wm_setwinner 1

		wm_endround
	}
}




///////////////////////////////////////////////
//                                           //
//              SPAWNS  &  CP                //
//                                           //
///////////////////////////////////////////////

// ================================================
neutral_cp_toi
{
	trigger show_neutral_cabinet			// Show Neutral Closed CP
	{
		setstate neutral_cp_closed default
		setstate neutral_cp_closed_model default
	}

	trigger hide_neutral_cabinet			// Hide Neutral Closed CP
	{
		setstate neutral_cp_closed invisible
		setstate neutral_cp_closed_model invisible
	}
}

// ================================================
allied_cp_open
{
	spawn
	{
		wait 100
		constructible_class 2			// Dyno+Satchel

		trigger self disable_cp_features		// Default charge bar times
	}

	trigger disable_cp_features
	{
		setstate allied_cp_open_model invisible	// Hide Open CP model

		setchargetimefactor 1 soldier 1
		setchargetimefactor 1 lieutenant 1
		setchargetimefactor 1 medic 1
		setchargetimefactor 1 engineer 1
		setchargetimefactor 1 covertops 1

		sethqstatus 1 0			// Landmines team warning message
		disablespeaker allied_cp_sound		// Disable morse code sound
	}

	trigger enable_cp_features
	{
		setstate allied_cp_open_model default	// Show open CP model

		setchargetimefactor 1 soldier 0.75
		setchargetimefactor 1 lieutenant 0.75
		setchargetimefactor 1 medic 0.75
		setchargetimefactor 1 engineer 0.75
		setchargetimefactor 1 covertops 0.75
		
		globalaccum 6 set 1
		
		wm_objective_status 4 0 2
        wm_objective_status 4 1 1
        
        // ENABLE NEW SPAWN
        trigger allied2spawn_wobj on

		sethqstatus 1 1			// Landmines team warning message
		enablespeaker allied_cp_sound		// Enable morse code sound
		      	
      // If first time, then set new spawn as default
      accum 3 abort_if_equal 1
      accum 3 set 1      
      
      setautospawn "CP Spawn"	1	// Set Allies to forward spawn
	}

	buildstart final
	{
		trigger neutral_cp_toi hide_neutral_cabinet	// Hide Neutral CP model+clip brush
	}

	built final
	{
		trigger self enable_cp_features		// Increase charge bar times

		wm_announce "Allied Command Post constructed. Charge speed increased!"
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_compost_constructed_allies"
		wm_teamvoiceannounce 1 "allies_hq_compost_constructed"
		wm_removeteamvoiceannounce 1 "allies_hq_compost_construct"
		// *----------------------------------- vo ------------------------------------------*
	}

	decayed final
	{
		setstate allied_cp_open_model invisible	// Hide Open CP model
		trigger neutral_cp_toi show_neutral_cabinet	// Show Neutral CP model+clip brush
	}

	death
	{
	  globalaccum 6 set 0
		
	  wm_objective_status 4 0 0
      wm_objective_status 4 1 0
		
	  //DISABLE NEW SPAWN
      trigger allied2spawn_wobj off
      
		trigger neutral_cp_toi show_neutral_cabinet	// Show Neutral CP model+clip brush
		trigger self disable_cp_features		// Default charge bar times

		wm_announce "Axis team has destroyed the Allied Command Post!"
		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"
		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"
		wm_teamvoiceannounce 0 "axis_hq_compost_construct"
		wm_teamvoiceannounce 1 "allies_hq_compost_damaged"
		// *----------------------------------- vo ------------------------------------------*
	}
}

// ================================================
axis_cp_open
{
	spawn
	{
		wait 100
		constructible_class 2			// Dyno+Satchel

		trigger self disable_cp_features		// Default charge bar times
	}

	trigger disable_cp_features
	{
		setstate axis_cp_open_model invisible	// Hide Open CP model

		setchargetimefactor 0 soldier 1
		setchargetimefactor 0 lieutenant 1
		setchargetimefactor 0 medic 1
		setchargetimefactor 0 engineer 1
		setchargetimefactor 0 covertops 1

		sethqstatus 0 0			// Landmines team warning message
		disablespeaker axis_cp_sound		// Disable morse code sound
	}

	trigger enable_cp_features
	{
		setstate axis_cp_open_model default	// Show open CP model

		setchargetimefactor 0 soldier 0.75
		setchargetimefactor 0 lieutenant 0.75
		setchargetimefactor 0 medic 0.75
		setchargetimefactor 0 engineer 0.75
		setchargetimefactor 0 covertops 0.75

		sethqstatus 0 1			// Landmines team warning message
		enablespeaker axis_cp_sound		// Enable morse code sound
	}

	buildstart final
	{
		trigger neutral_cp_toi hide_neutral_cabinet	// Hide Neutral CP model+clip brush
	}

	built final
	{
		trigger self enable_cp_features		// Increase charge bar times

		wm_announce "Axis Command Post constructed. Charge speed increased!"
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_compost_constructed"
		wm_teamvoiceannounce 1 "allies_hq_compost_constructed_axis"
		wm_removeteamvoiceannounce 0 "axis_hq_compost_construct"
		// *----------------------------------- vo ------------------------------------------*
	}

	decayed final
	{
		setstate axis_cp_open_model invisible	// Hide Open CP model
		trigger neutral_cp_toi show_neutral_cabinet	// Show Neutral CP model+clip brush
	}

	death
	{
		trigger neutral_cp_toi show_neutral_cabinet	// Show Neutral CP model+clip brush
		trigger self disable_cp_features		// Default charge bar times

		wm_announce "Allied team has destroyed the Axis Command Post!"
		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hq_compost_construct"
		wm_addteamvoiceannounce 1 "allies_hq_compost_construct"
		wm_teamvoiceannounce 0 "axis_hq_compost_damaged"
		wm_teamvoiceannounce 1 "allies_hq_compost_construct"
		// *----------------------------------- vo ------------------------------------------*
	}
}

//=============================== spawns

allied1spawn_spawns
{
   	spawn
	{
	  wait 50
	}
} 

allied1spawn_wobj
{
   	spawn
	{
	  wait 200
	}
	trigger off
    {
      setstate allied1spawn_wobj invisible
      alertentity allied1spawn_spawns
      setstate allied1spawn_spawns invisible
    }
    trigger on
    {
      setstate allied1spawn_wobj default
      alertentity allied1spawn_spawns
      setstate allied1spawn_spawns default
    }
	trigger allied_capture 
	{
		//
	}
    trigger axis_capture
    {
	    //
    }
} 

allied2spawn_spawns
{
   	spawn
	{
	  wait 50
	  setstate allied2spawn_spawns invisible
	}
} 

allied2spawn_wobj
{
   	spawn
	{
	  wait 200
	  setstate allied2spawn_wobj invisible
	}
	trigger off
    {
      setstate allied2spawn_wobj invisible
      setstate allied2spawn_spawns invisible
	  alertentity allied2spawn_spawns
    }
    trigger on
    {
      setstate allied2spawn_wobj default
      setstate allied2spawn_spawns default
	  alertentity allied2spawn_spawns
      
      setautospawn "CP Spawn"	1
    }
	trigger allied_capture 
	{
		//
	}
    trigger axis_capture
    {
	    //
    }
} 


allied3spawn_spawns
{
   	spawn
	{
	  wait 50
	  setstate allied3spawn_spawns invisible
	}
} 

allied3spawn_wobj
{
   	spawn
	{
	  wait 200
	  setstate allied3spawn_wobj invisible
	}
	trigger off
    {
      setstate allied3spawn_wobj invisible
      setstate allied3spawn_spawns invisible
	  alertentity allied3spawn_spawns
    }
    trigger on
    {
      setstate allied3spawn_wobj default
      setstate allied3spawn_spawns default
	  alertentity allied3spawn_spawns
      
	  // abort if cp already been done.
      globalaccum 6 abort_if_equal 1
      
      setautospawn "Allied flag spawn"	1
    }
	trigger allied_capture 
	{
		//
	}
    trigger axis_capture
    {
	    //
    }
} 

axis1spawn_spawns
{
   	spawn
	{
	  wait 500
	remove
	}
} 

axis1spawn_wobj
{
   	spawn
	{
	  wait 200
	}
	trigger off
    {
      setstate axis1spawn_wobj invisible
      setstate axis1spawn_spawns invisible
	  alertentity axis1spawn_spawns
    }
    trigger on
    {
      setstate axis1spawn_wobj default
      setstate axis1spawn_spawns default
	  alertentity axis1spawn_spawns
    }
	trigger allied_capture 
	{
		//
	}
    trigger axis_capture
    {
	    //
    }
} 

axis2spawn_spawns
{
   	spawn
	{
	  wait 50
	}
}


axis2spawn_wobj
{
   	spawn
	{
	  wait 200
	}
	trigger off
    {
      setstate axis2spawn_wobj invisible
      setstate axis2spawn_spawns invisible
	  alertentity axis2spawn_spawns
    }
    trigger on
    {
      setstate axis2spawn_wobj default
      setstate axis2spawn_spawns default
	  alertentity axis2spawn_spawns
    }
	trigger allied_capture 
	{
		//
	}
    trigger axis_capture
    {
	    //
    }
} 

flag1_flag
{
	spawn
	{
		wait 500
		remove
	}
	
	trigger allied_capture
	{
		globalaccum 3 abort_if_equal 1
		globalaccum 3 set 1
		trigger axis1spawn_wobj off
		trigger allied3spawn_wobj on
		
		wm_announce "The Allies have captured the forward bunker!"
								
		wm_objective_status 3 1 1		
		wm_objective_status 3 0 0
						
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "radar_axis_bunker_captured"

		wm_teamvoiceannounce 1 "radar_allies_bunker_captured"

		wm_removeteamvoiceannounce 0 "radar_axis_bunker_stop"

		wm_removeteamvoiceannounce 1 "radar_allies_bunker_capture"
		// *---------------------------------------------------------------------------------*
		
		// abort if CP is done
		globalaccum 6 abort_if_equal 1
		
		setautospawn "Allied flag spawn"	1
		
	}
	
	trigger axis_capture
	{
		globalaccum 3 abort_if_equal 0
		globalaccum 3 set 0
		trigger axis1spawn_wobj on
		trigger allied3spawn_wobj off
		
		wm_announce "The Axis have reclaimed the forward bunker!"
								
		wm_objective_status 3 1 0		
		wm_objective_status 3 0 1
        
		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "radar_axis_bunker_stop"

		wm_addteamvoiceannounce 1 "radar_allies_bunker_capture"

		wm_teamvoiceannounce 0 "radar_axis_bunker_reclaimed"

		wm_teamvoiceannounce 1 "radar_allies_bunker_reclaimed"
		// *---------------------------------------------------------------------------------*
	}
	
	trigger force_allied
	{
		setstate flag1_flag invisible
		globalaccum 3 abort_if_equal 1
		globalaccum 3 set 1
		trigger axis1spawn_wobj off
		trigger allied3spawn_wobj on
		
		wm_announce "The Allies have secured the forward bunker!"
								
		wm_objective_status 3 1 1		
		wm_objective_status 3 0 2
						
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "radar_axis_bunker_captured"

		wm_teamvoiceannounce 1 "radar_allies_bunker_captured"

		wm_removeteamvoiceannounce 0 "radar_axis_bunker_stop"

		wm_removeteamvoiceannounce 1 "radar_allies_bunker_capture"
		// *---------------------------------------------------------------------------------*
		
		// abort if CP is done
		globalaccum 6 abort_if_equal 1
		
		setautospawn "Allied flag spawn"	1
		
	}
}




///////////////////////////////////////////////
//                                           //
//             OTHER OBJECTIVES              //
//                                           //
///////////////////////////////////////////////


maingate
{
	spawn
	{
		wait 500
		constructible_class 1
		remove
	}
	
	death
	{
		wm_announce "The main gate has been destroyed!"
										
		wm_objective_status 2 1 1		
		wm_objective_status 2 0 2
		
		globalaccum 2 set 1
		
		trigger flag1_flag force_allied
		trigger mtd_sm do_open
		
				
		// *----------------------------------- vo ------------------------------------------*
		
		//wm_addteamvoiceannounce 0 "radar_axis_radars_defend"
		//wm_addteamvoiceannounce 1 "radar_allies_radars_steal"

		wm_teamvoiceannounce 0 "radar_axis_entrance1_destroyed"
		//wm_teamvoiceannounce 0 "radar_axis_radars_defend"

		wm_teamvoiceannounce 1 "radar_allies_entrance1_destroyed"
		//wm_teamvoiceannounce 1 "radar_allies_radars_steal"
				
		//wm_teamvoiceannounce 1 "allies_hq_objective_destroyed"
		
		wm_removeteamvoiceannounce 0 "radar_axis_entrances_defend"
		wm_removeteamvoiceannounce 1 "radar_allies_entrances_destroy"
		
		// "Construct the command post!" voice over, unless its already been done.
        globalaccum 6 abort_if_equal 1
        		
		wm_teamvoiceannounce 1 "allies_hq_compost_construct"
		// *---------------------------------------------------------------------------------*
	}
}

mtd_td
{
	spawn
	{
		wait 500
		remove
	}
	trigger do_hide
	{
		setstate mtd_td invisible
	}
}

mtd_sm
{
	spawn
	{
		wait 500
		remove
	}
	
	trigger do_open
	{
		setstate mtd_sm default
		trigger mtd_td do_hide
		wait 100
		faceangles 0 -90 0 1500
	}
}

sidedoor
{
	spawn
	{
		wait 500
		constructible_class 1
		remove		
	}
	
	death
	{
		wait 100
		
		wm_announce "The side door has been destroyed!"
		trigger sidedoor_toi do_hide

		//Sidedoor
		wm_objective_status 5 1 1
		wm_objective_status 5 0 2
	}
}

sidedoor_toi
{
	spawn
	{
		wait 50	
	}
	
	trigger do_hide
	{
		setstate sidedoor_toi invisible
		setstate sidedoor_cmm invisible
	}
}



////////////////////////////////////////////////////
//=================================================
////////////////////////////////////////////////////

keycard_CMM
{
	spawn
	{
	wait 500
	remove
	}
}

keycard_cap
{
	spawn
	{
	}
	death
	{
		wm_announce "The Allies have captured the keycard. The generator has been started!"
		//open doors
		
		//generator effects
		trigger keycard_capmodel_red hide
		trigger keycard_capmodel show
		trigger gen_pistons turnon
		trigger gen_speaker turnon
		trigger gen_speaker2 turnon
		
		//Generator
		wm_objective_status 5 1 1
		wm_objective_status 5 0 2
		
		trigger rollerdoor1 do_up
		trigger rollerdoor2 do_up
		trigger rollerdoor3 do_up
		trigger rollerdoor4 do_up
		
		//let truck get stolen now
		wait 1500		
		trigger truck add_goldbar
	}
}

keycard_capmodel_red
{
	spawn
	{
		wait 100
		trigger self show
	}
	trigger show
	{
		setstate keycard_capmodel_red default
	}
	trigger hide
	{
		setstate keycard_capmodel_red invisible
	}
}

keycard_capmodel
{
	spawn
	{
		wait 100
		trigger self hide
	}
	trigger show
	{
		setstate keycard_capmodel default
	}
	trigger hide
	{
		setstate keycard_capmodel invisible
	}
}

keycard_flag
{
    spawn
    {
	    wait 200
    }
    trigger stolen 
    {
    	//when the objective is taken 
    	// Hide command map marker of keycard at table
    	setstate keycard_CMM invisible 
	}
	trigger dropped
	{
		//when the player carrying the objective is killed 
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 1 "allies_hq_objective_lost"
		// *---------------------------------------------------------------------------------*
	}
	trigger returned
	{
		//when defending team touches the dropped objective
		// Show command map marker of keycard at table
		setstate keycard_CMM default
	} 
	trigger captured
	{
		//when the objective is delivered to its deliverypoint 
		
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_objective_lost"
		wm_teamvoiceannounce 1 "allies_hq_objective_captured"
		// *---------------------------------------------------------------------------------*
	}
}

gen_pistons
{
	spawn
	{
		wait 100
				
		setstate gen_pistons1 invisible
		setstate gen_pistons2 invisible
		setstate gen_pistons3 invisible
	}
	
	trigger turnon
	{
		setstate gen_pistons invisible
		setstate gen_pistons1 default
		setstate gen_pistons2 default
		setstate gen_pistons3 default
	}
}

gen_speaker
{
	spawn
	{
		wait 100
		stopsound
	}
	
	trigger turnon
	{
		trigger self sound_idle	
	}
	
	trigger sound_idle
	{
		playsound sound/world/machine_02.wav looping
	}
}

gen_speaker2
{
	spawn
	{
		wait 100
		stopsound
	}
	
	trigger turnon
	{
		trigger self sound_idle	
	}
	
	trigger sound_idle
	{
		playsound sound/world/transformer.wav looping
	}
}

rollerdoor1
{
	spawn
	{
		wait 200
		gotomarker rd1_pc_0 1000
	}
	
	trigger do_up
	{
		wait 500
		playsound sound/movers/misc/garage_door_start_01.wav
		wait 400
		playsound sound/movers/misc/garage_door_loop_01.wav looping forever
		gotomarker rd1_pc_1 80 wait
		stopsound
		playsound sound/movers/misc/garage_door_end_01.wav
	}
}

rollerdoor2
{
	spawn
	{
		wait 200
		gotomarker rd2_pc_0 1000
	}
	
	trigger do_up
	{
		wait 500
		playsound sound/movers/misc/garage_door_start_01.wav
		wait 400
		playsound sound/movers/misc/garage_door_loop_01.wav looping forever
		gotomarker rd2_pc_1 80 wait
		stopsound
		playsound sound/movers/misc/garage_door_end_01.wav
	}
}

rollerdoor3
{
	spawn
	{
		wait 200
		gotomarker rd3_pc_0 1000
	}
	
	trigger do_up
	{
		wait 500
		playsound sound/movers/misc/garage_door_start_01.wav
		wait 400
		playsound sound/movers/misc/garage_door_loop_01.wav looping forever
		gotomarker rd3_pc_1 80 wait
		stopsound
		playsound sound/movers/misc/garage_door_end_01.wav
	}
}

rollerdoor4
{
	spawn
	{
		wait 200
		gotomarker rd4_pc_0 1000
	}
	
	trigger do_up
	{
		wait 500
		playsound sound/movers/misc/garage_door_start_01.wav
		wait 400
		playsound sound/movers/misc/garage_door_loop_01.wav looping forever
		gotomarker rd4_pc_1 80 wait
		stopsound
		playsound sound/movers/misc/garage_door_end_01.wav
	}
}

// **********************************************
// ****************** TRUCK STUFF ***************
// **********************************************

truck_smoke
{
	spawn
	{
		wait 50
		attachtotag truck tag_wfront
		//setstate truck_smoke invisible
	}
}

// sound "thread"
truck_engine
{
	spawn
	{
		wait 200
		attachtotag truck tag_wfront

		//trigger truck_engine sound_idle
	}

	trigger start
	{
		trigger truck_engine sound_start
		wait 950
		trigger truck_engine sound_move
	}

	trigger stop
	{
		trigger truck_engine sound_stop
		wait 950
		trigger truck_engine sound_idle
	}

	// ========================================
	// sound events
	trigger sound_idle
	{
		playsound sound/vehicles/truck/truck_idle.wav looping
	}

	trigger sound_start
	{
		stopsound
		playsound sound/vehicles/truck/truck_revup.wav volume 96
	}

	trigger sound_move
	{
		playsound sound/vehicles/truck/truck_move.wav looping
	}

	trigger sound_stop
	{
		stopsound
		playsound sound/vehicles/truck/truck_revdown.wav volume 96
	}

	trigger sound_death
	{
		stopsound
		playsound sound/vehicles/truck/truck_stop.wav volume 96
	}
	
	trigger sound_silence
	{
		stopsound
		playsound sound/vehicles/truck/truck_stop.wav volume 96
	}

	// ========================================
	// ========================================
}

truck_build
{
	spawn
	{
		wait 500

		attachtotag truck tag_wback
	}
}

truck_construct
{
	spawn
	{
		wait 500
		
		kill truck
		
		constructible_class 2
		constructible_constructxpbonus 10
	}

	built final
	{
		trigger truck do_rebirth
		globalaccum 7 set 1

		wm_announce "The Truck has been repaired!"
	}
}

// digibob: ok, for once i'm gonna PLAN this one, so NOTHING WILL BREAK EVAR
// ============================================================================
// accum 0, gold bars collected
// accum 1
//  - bit 0: barrier 1 status 	( 0 = destroyed, 	1 = built 		)
//  - bit 1: barrier 2 status 	( 0 = destroyed, 	1 = built 		)
//  - bit 2: spline status 		( 0 = not moving, 	1 = moving 		)
//  - bit 3: stuck check flag 	( 0 = not stuck, 	1 = stuck 		)
//  - bit 4: script lockout 	( 0 = no lockout, 	1 = lockout		)
//  - bit 5: blank 				( 									)
//  - bit 6: temp register 		(XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)
//  - bit 7: death status 		( 0 = alive, 		1 = dead		)
//  - bit 8: player check 		( 0 = players, 		1 = no players	)
//  - bit 9: visible state		( 0 = alive, 		1 = dead		)
// accum 2, blank
// accum 3, current movement loop position
// accum 4, stop counter
// accum 5, blank
// accum 6, blank
// accum 7, blank
// ============================================================================
// spline points are tspln_X with X = 1 to 23
// ============================================================================
// wheel events:
//  - wheels_forward
//  - wheels_backward
//  - wheels_stop

truck
{
	spawn
	{
		faceangles 0 0 0 50
		//trigger truck add_goldbar
		
		accum 1 bitset 9				// we're now visibly dead

		setstate truck_smoke default

		trigger truck_engine sound_silence
		trigger truck wheels_stop
		
		changemodel models/mapobjects/blitz_sd/blitzbody_damaged.md3
	}

	// ========================================
	// wheeeeeeeeeeeeeeels. eeels. ls.
	trigger wheels_forward
	{
		trigger truck_bwheel2 forward
		trigger truck_fwheel forward
	}

	trigger wheels_backward
	{
		trigger truck_bwheel2 backward
		trigger truck_fwheel backward
	}

	trigger wheels_stop
	{
		trigger truck_bwheel2 stop
		trigger truck_fwheel stop
	}

	// ========================================
	// ========================================

	trigger add_goldbar
	{
		accum 0 set 2


		//trigger gold_full_0 show
		//trigger gold_trans_0 hide
		//trigger gold_crate secured

		//accum 0 abort_if_less_than 2

		//trigger gold_full_1 show
		//trigger gold_trans_1 hide
		
		wm_announce "Allied team has gained access to the truck!"

		//setstate goldbars_toi invisible
		//setstate goldbars_cm_marker invisible
	}

	trigger truck_escape_msg
	{
		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "axis_hq_truck_stop"

		wm_addteamvoiceannounce 1 "allies_hq_truck_escort"

		wm_teamvoiceannounce 0 "goldrush_axis_truck_stolen"

		wm_teamvoiceannounce 1 "goldrush_allies_truck_stolen"
		// *---------------------------------------------------------------------------------*
		
		//Stealtruck
		wm_objective_status 8 1 1
		wm_objective_status 8 0 2
	}

	// ========================================
	// movement

	trigger move_check
	{
		trigger truck stuck_check
		accum 1 abort_if_bitset 3

		trigger truck dispatch
	}

	trigger move
	{
		trigger truck move_check

		wait 500

		trigger truck move
	}

	// ========================================
	// ========================================


	trigger run_continue
	{
		trigger truck deathcheck
		trigger truck stopcheck
		trigger truck move
	}

	trigger run_1
	{
		globalaccum 7 abort_if_equal 0
		trigger truck_engine start
		trigger truck wheels_forward
		
		accum 1 bitset 2
		followspline 0 tspln_1 125 wait length 304 wait roll 0 2 dampin
		accum 1 bitreset 2

		accum 3 set 1

		trigger truck run_continue
	}

	trigger run_2
	{
		trigger self truck_escape_msg
		
		accum 1 bitset 2
		followspline 0 tspln_2 125 wait length 304 wait roll 2 -1 dampout
		accum 1 bitreset 2

		accum 3 set 2
		trigger truck run_continue
	}

	trigger run_3
	{
		accum 1 bitset 2
		followspline 0 tspln_3 125 wait length 304 wait roll 1 -1 dampout
		accum 1 bitreset 2

		accum 3 set 3

		trigger truck run_continue
	}

	trigger run_4
	{
		accum 1 bitset 2
		followspline 0 tspln_4 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 4
		trigger truck run_continue
	}

	trigger run_5
	{
		accum 1 bitset 2
		followspline 0 tspln_5 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 5
		trigger truck run_continue
	}

	trigger run_6
	{
		accum 1 bitset 2
		followspline 0 tspln_6 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 6
		trigger truck run_continue
	}

	trigger run_7
	{
		accum 1 bitset 2
		followspline 0 tspln_7 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 7
		trigger truck run_continue
	}

	trigger run_8
	{
		accum 1 bitset 2
		followspline 0 tspln_8 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 8
		trigger truck run_continue
	}

	trigger run_9
	{
		accum 1 bitset 2
		followspline 0 tspln_9 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 9
		trigger truck run_continue
	}

	trigger run_10
	{
		accum 1 bitset 2
		followspline 0 tspln_10 125 wait length 304 wait roll 0 -2 dampin
		accum 1 bitreset 2

		accum 3 set 10
		trigger truck stuck_check_barrier3_built_msg
		
		trigger truck run_continue
	}

	trigger run_11
	{
		accum 1 bitset 2
		followspline 0 tspln_11 125 wait length 304 wait roll -2 0
		accum 1 bitreset 2

		accum 3 set 11
		trigger truck run_continue
	}

	trigger run_12
	{
		accum 1 bitset 2
		followspline 0 tspln_12 125 wait length 304 wait roll -2 -1 dampin
		accum 1 bitreset 2

		accum 3 set 12
		trigger truck run_continue
	}

	trigger run_13
	{
		// **************************
		trigger defense3 remove
		// **************************
		
		accum 1 bitset 2
		followspline 0 tspln_13 125 wait length 304 wait roll -3 0 dampout
		accum 1 bitreset 2

		accum 3 set 13
				
		trigger truck run_continue
	}

	trigger run_14
	{
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "goldrush_axis_truck_barrier1"

		wm_teamvoiceannounce 1 "goldrush_allies_truck_barrier1"
		// *---------------------------------------------------------------------------------*
		
		accum 1 bitset 2
		followspline 0 tspln_14 125 wait length 304 wait roll -3 +3 dampout
		accum 1 bitreset 2

		accum 3 set 14
		trigger truck run_continue
	}

	trigger run_15
	{
		accum 1 bitset 2
		followspline 0 tspln_15 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 15
				
		trigger truck run_continue
	}

	trigger run_16
	{
		
		accum 1 bitset 2
		followspline 0 tspln_16 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 16
		
		trigger truck run_continue
	}

	trigger run_17
	{
		accum 1 bitset 2
		followspline 0 tspln_17 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 17

		trigger truck run_continue
	}

	trigger run_18
	{
		accum 1 bitset 2
		followspline 0 tspln_18 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 18
		trigger truck run_continue
	}

	trigger run_19
	{
		accum 1 bitset 2
		followspline 0 tspln_19 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 19
		trigger truck run_continue
	}

	trigger run_20
	{
		accum 1 bitset 2
		followspline 0 tspln_20 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 20
		trigger truck run_continue
	}

	trigger run_21
	{
		accum 1 bitset 2
		followspline 0 tspln_21 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 21
		trigger truck run_continue
	}

	trigger run_22
	{
		accum 1 bitset 2
		followspline 0 tspln_22 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 22
		
		trigger self stuck_check_maingate_msg
		
		trigger truck run_continue
	}

	trigger run_23
	{
		accum 1 bitset 2
		followspline 0 tspln_23 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 23
		trigger truck run_continue
	}

	trigger run_24
	{
		accum 1 bitset 2
		followspline 0 tspln_24 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 24

		trigger truck run_continue
	}
	
	trigger run_25
	{
		accum 1 bitset 2
		followspline 0 tspln_25 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 25
		
		// stop here for gate

		trigger truck run_continue
	}
	
	trigger run_26
	{
		accum 1 bitset 2
		followspline 0 tspln_26 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 26
		
		// change allied spawn back to flag (closer)
		setautospawn "Allied flag spawn"	1

		trigger truck run_continue
	}
	
	trigger run_27
	{
		accum 1 bitset 2
		followspline 0 tspln_27 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 27
		
		trigger truck stuck_check_barrier4_built_msg

		trigger truck run_continue
	}
	
	trigger run_28
	{
		accum 1 bitset 2
		followspline 0 tspln_28 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 28
		
		trigger truck run_continue
	}
	
	trigger run_29
	{
		accum 1 bitset 2
		followspline 0 tspln_29 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 29
		
		trigger truck run_continue
	}
	
	trigger run_30
	{
		// **************************
		trigger defense4 remove
		// **************************
		
		accum 1 bitset 2
		followspline 0 tspln_30 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 30
		
		trigger truck run_continue
	}
	
	trigger run_31
	{	
		
		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "goldrush_axis_truck_barrier2"

		wm_teamvoiceannounce 1 "goldrush_allies_truck_barrier2"
		// *---------------------------------------------------------------------------------*
		
		accum 1 bitset 2
		followspline 0 tspln_31 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 31

		trigger truck run_continue
	}
	
	trigger run_32
	{		
		accum 1 bitset 2
		followspline 0 tspln_32 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 32

		trigger truck run_continue
	}
	
	trigger run_33
	{		
		accum 1 bitset 2
		followspline 0 tspln_33 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 33

		trigger truck run_continue
	}
	
	trigger run_34
	{
		accum 1 bitset 2
		followspline 0 tspln_34 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 34

		trigger truck run_continue
	}
	
	trigger run_35
	{
		accum 1 bitset 2
		followspline 0 tspln_35 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 35

		trigger truck run_continue
	}
	
	trigger run_36
	{
		accum 1 bitset 2
		followspline 0 tspln_36 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 36

		trigger truck run_continue
	}
	
	trigger run_37
	{
		accum 1 bitset 2
		followspline 0 tspln_37 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 37

		trigger truck run_continue
	}
	
	trigger run_38
	{
		accum 1 bitset 2
		followspline 0 tspln_38 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 38

		trigger truck run_continue
	}
	
	trigger run_39
	{
		accum 1 bitset 2
		followspline 0 tspln_39 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 39

		trigger truck wheels_stop

		trigger game_manager cap_truck
		
	}
	
	trigger run_40
	{
		accum 1 bitset 2
		//followspline 0 tspln_40 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 40
	}
	
	trigger run_41
	{
		accum 1 bitset 2
		//followspline 0 tspln_41 125 wait length 304
		accum 1 bitreset 2

		accum 3 set 41		
	}

	trigger dispatch
	{
		//accum 0 abort_if_not_equal 2
		accum 3 trigger_if_equal 0 	truck run_1
		accum 3 trigger_if_equal 1 	truck run_2
		accum 3 trigger_if_equal 2	truck run_3
		accum 3 trigger_if_equal 3 	truck run_4
		accum 3 trigger_if_equal 4 	truck run_5
		accum 3 trigger_if_equal 5 	truck run_6
		accum 3 trigger_if_equal 6 	truck run_7
		accum 3 trigger_if_equal 7 	truck run_8
		accum 3 trigger_if_equal 8 	truck run_9
		accum 3 trigger_if_equal 9 	truck run_10
		accum 3 trigger_if_equal 10	truck run_11
		accum 3 trigger_if_equal 11	truck run_12
		accum 3 trigger_if_equal 12	truck run_13
		accum 3 trigger_if_equal 13	truck run_14
		accum 3 trigger_if_equal 14	truck run_15
		accum 3 trigger_if_equal 15	truck run_16
		accum 3 trigger_if_equal 16	truck run_17
		accum 3 trigger_if_equal 17	truck run_18
		accum 3 trigger_if_equal 18	truck run_19
		accum 3 trigger_if_equal 19	truck run_20
		accum 3 trigger_if_equal 20	truck run_21
		accum 3 trigger_if_equal 21	truck run_22
		accum 3 trigger_if_equal 22	truck run_23
		accum 3 trigger_if_equal 23	truck run_24
		accum 3 trigger_if_equal 24	truck run_25
		accum 3 trigger_if_equal 25	truck run_26
		accum 3 trigger_if_equal 26	truck run_27
		accum 3 trigger_if_equal 27	truck run_28
		accum 3 trigger_if_equal 28	truck run_29
		accum 3 trigger_if_equal 29	truck run_30
		accum 3 trigger_if_equal 30	truck run_31
		accum 3 trigger_if_equal 31	truck run_32
		accum 3 trigger_if_equal 32	truck run_33
		accum 3 trigger_if_equal 33	truck run_34
		accum 3 trigger_if_equal 34	truck run_35
		accum 3 trigger_if_equal 35	truck run_36
		accum 3 trigger_if_equal 36	truck run_37
		accum 3 trigger_if_equal 37	truck run_38
		accum 3 trigger_if_equal 38	truck run_39
		accum 3 trigger_if_equal 39	truck run_40
		accum 3 trigger_if_equal 40	truck run_41
	}

	// ========================================
	// barrier checking
	// digibob: since we cant return variables, just use bit 3 of accum 1 as a register... mmmm assembly......

	trigger stuck_check
	{
		accum 1 bitreset 3

		trigger truck stuck_check_gold
		trigger truck stuck_check_build
		trigger truck stuck_check_barrier3
		trigger truck stuck_check_barrier4
		trigger truck stuck_check_maingate
		trigger truck stuck_check_scriptlockout
		trigger truck stuck_check_finished
	}

	trigger stuck_check_finished
	{
		accum 3 abort_if_not_equal 40

		accum 1 bitset 3
	}

	trigger stuck_check_scriptlockout
	{
		accum 1 abort_if_not_bitset 4

		accum 1 bitset 3
	}

	trigger stuck_check_gold
	{
		accum 3 abort_if_not_equal 0

		accum 0 abort_if_equal 2

		accum 1 bitset 3
	}
	
	trigger stuck_check_build
	{
		globalaccum 7 abort_if_equal 1

		accum 1 bitset 3
	}

	trigger stuck_check_barrier3
	{
		accum 3 abort_if_not_equal 12

		accum 1 abort_if_not_bitset 0

		accum 1 bitset 3
	}
	
	trigger stuck_check_maingate
	{
		accum 3 abort_if_not_equal 24

		globalaccum 2 abort_if_equal 1

		accum 1 bitset 3
	}
	
	trigger stuck_check_maingate_msg
	{
		globalaccum 2 abort_if_equal 1

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 1 "radar_allies_entrances_destroy"
		// *---------------------------------------------------------------------------------*
	}

	trigger stuck_check_barrier3_built_msg
	{
		accum 1 abort_if_not_bitset 0

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 1 "goldrush_allies_truckbar_destroy"
		// *---------------------------------------------------------------------------------*
	}

	trigger stuck_check_barrier4
	{
		accum 3 abort_if_not_equal 29

		accum 1 abort_if_not_bitset 1

		accum 1 bitset 3
	}

	trigger stuck_check_barrier4_built_msg
	{
		accum 1 abort_if_not_bitset 1

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 1 "goldrush_allies_truckbar_destroy"
		// *---------------------------------------------------------------------------------*
	}

	// ========================================
	// ========================================




	// ========================================
	// stop check

	trigger stopcheck_setup
	{
		accum 1 bitset 6				// stop if we're stuck/no-one's pushing :)

		accum 1 abort_if_bitset 8		// no one in the trigger, abort

		trigger truck stuck_check		// call the stop check function
		accum 1 abort_if_bitset 3		// we're stuck so break out

		accum 1 bitreset 6				// we're free to keep going
	}

	trigger stopcheck
	{
		trigger truck stopcheck_setup
		accum 1 abort_if_not_bitset 6

		trigger truck script_lockout

		// Any just stopped moving stuff goes here
		trigger truck_engine stop
		trigger truck 		wheels_stop
		// <<<<< stop animation goes here

		trigger truck script_lockout_stop
		resetscript
	}

	// ========================================
	// ========================================




	// ========================================
	// script lockouts

	trigger script_lockout
	{
		accum 1 bitset 4
	}

	trigger script_lockout_stop
	{
		accum 1 bitreset 4
	}

	// ========================================
	// ========================================


	// ========================================
	// enable/disable

	trigger truck_enable
	{
		globalaccum 7 abort_if_equal 0
		trigger truck stuck_check
		accum 1 abort_if_bitset 3 	// stuck check

		accum 4 set 0				// reset stop counter
		accum 1 bitreset 8			// reset stop check

		accum 1 abort_if_bitset 2 	// already following spline
		accum 1 abort_if_bitset 4 	// script lockout

		accum 1 abort_if_bitset 7 	// death check

		//accum 0 abort_if_not_equal 2
		// Any just started moving stuff goes here
		trigger truck_engine start
		trigger truck wheels_forward
		// <<<<< start animation goes here
		trigger truck move
	}

	trigger truck_disable
	{
		accum 4 inc 1				// up the stop counter
		accum 4 abort_if_less_than 2

		accum 1 bitset 8			// set stop check

		trigger truck deathcheck
	}

	// ========================================
	// ========================================

	// ========================================
	// death / rebirth

	rebirth
	{
		accum 1 bitreset 7 // we're alive again
		accum 1 bitreset 9 // we're visibly alive

		changemodel models/mapobjects/blitz_sd/blitzbody.md3
		//changemodel models/mapobjects/blitz_sd/blitzbody_damaged.md3

		setstate truck_smoke invisible

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_truck_repaired_allies"

		wm_teamvoiceannounce 1 "allies_hq_truck_repaired"
		// *---------------------------------------------------------------------------------*

		trigger truck move
	}
	
	trigger do_rebirth
	{
		accum 1 bitreset 7 // we're alive again
		accum 1 bitreset 9 // we're visibly alive

		changemodel models/mapobjects/blitz_sd/blitzbody.md3
		//changemodel models/mapobjects/blitz_sd/blitzbody_damaged.md3

		trigger truck_engine sound_idle
		setstate truck_smoke invisible

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_truck_repaired_allies"

		wm_teamvoiceannounce 1 "allies_hq_truck_repaired"
		// *---------------------------------------------------------------------------------*

		//trigger truck move
	}

	death
	{
		accum 1 bitset 7
	}

	trigger deathcheck
	{
		accum 1 abort_if_not_bitset 7	// are we dead?
		accum 1 abort_if_bitset 9		// are we not already visibly dead?
		accum 1 abort_if_bitset 2		// are we not following a spline?
		accum 1 abort_if_bitset 4		// are we not in a script lockout?

		accum 1 bitset 9				// we're now visibly dead

		wm_announce "The Truck has been damaged!"

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "axis_hq_truck_damaged"

		wm_teamvoiceannounce 1 "allies_hq_truck_damaged_axis"
		// *---------------------------------------------------------------------------------*

		setstate truck_smoke default
		kill truck_construct

		trigger truck_engine sound_death
		//trigger truck tracks_stop		// truck with tracks? i don't think so
		trigger truck wheels_stop
		// <<<< stop anim goes here

		changemodel models/mapobjects/blitz_sd/blitzbody_damaged.md3

		resetscript
	}

	// ========================================
	// ========================================
	
	
	// ========================================
	// barriers

	trigger enable_stage1
	{
		accum 1 bitreset 0
	}

	trigger disable_stage1
	{
		accum 1 bitset 0
	}

	trigger enable_stage2
	{
		accum 1 bitreset 1
	}

	trigger disable_stage2
	{
		accum 1 bitset 1
	}

	// ========================================
	// ========================================
}

truck_bwheel2
{
	spawn
	{
		wait 500

		attachtotag truck tag_wback
	}

	trigger forward
	{
		setrotation 130 0 0
	}

	trigger backward
	{
		setrotation -130 0 0
	}

	trigger stop
	{
		stoprotation
	}
}

truck_fwheel
{
	spawn
	{
		wait 500

		attachtotag truck tag_wfront
	}

	trigger forward
	{
		setrotation 130 0 0
	}

	trigger backward
	{
		setrotation -130 0 0
	}

	trigger stop
	{
		stoprotation
	}
}

truck_trigger
{
	spawn
	{
		wait 500

		attachtotag truck tag_wback
	}
}

truck_disabler
{
	trigger run
	{
		trigger truck truck_disable
	}
}

truck_enabler
{
	trigger run
	{
		trigger truck truck_enable
	}
}

gold_full_1
{
	spawn
	{
		wait 500
		attachtotag truck tag_obj2
		faceangles 0 90 0 50
		//faceangles 0 90 0 50

		setstate gold_full_1 default
	}
}

gold_full_0
{
	spawn
	{
		wait 500
		attachtotag truck tag_obj1
		faceangles 0 90 0 50

		setstate gold_full_1 default
	}
}


///////////////////////////
///////////////////////////   TRUCK BARRIERS
///////////////////////////

defense3
{
	spawn
	{
		wait 400
		setstate defense3_materials invisible
		setstate defense3_materials_clip invisible
		setstate defense3_flag invisible


		setstate defense3_wire invisible
		setstate defense3_hurt invisible
		setstate defense3_teeth1 invisible
		setstate defense3_teeth2 invisible
	}
}

defense4
{
	spawn
	{
		wait 400
		setstate defense4_materials invisible
		setstate defense4_materials_clip invisible
		setstate defense4_flag invisible


		setstate defense4_wire invisible
		setstate defense4_hurt invisible
		setstate defense4_teeth1 invisible
		setstate defense4_teeth2 invisible
	}

}